<template>
  <el-dialog
    :title="'购房情况查询'"

    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule"     v-loading="submitLoading"
    :element-loading-text="'正在提交'"
     ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="140px">

    
    <el-form-item label="登记中心" prop="djzx" v-if="false"    >
      <el-select v-model="dataForm.djzx" placeholder="登记中心" style="width:100%">
          <el-option
            v-for="item in dataForm.bankList"
            :key="item.bankid"
            :label="item.bankname"
            :value="item.bankid">
          </el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="网厅授权码" prop="sqm">
      <el-input v-model="dataForm.sqm" placeholder="网厅授权码"></el-input>
    </el-form-item>

    <el-row>
      <el-col :span="12">
        <el-form-item label="地市" prop="seRegion">
          <el-select  @change="selectChanged" v-model="dataForm.seRegion" placeholder="区域" style="width:100%">
              <el-option
                v-for="item in dataForm.seRegionList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="区县" prop="region">
          <el-select v-model="dataForm.region" placeholder="区域" style="width:100%">
              <el-option
                v-for="item in dataForm.regionList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>


    <el-form-item label="被查询人名称" prop="name">
      <el-input v-model="dataForm.name" placeholder="被查询人名称"></el-input>
    </el-form-item>
    <el-form-item label="被查询人证件号码" prop="idcode">
      <el-input v-model="dataForm.idcode" placeholder="被查询人证件号码"></el-input>
    </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()"  :disabled="submitLoading" >确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {

      return {
        visible: false,
        submitLoading: false,
        dataForm: {
          seRegion: '',
          region: '',
          name: '',
          idcode: '',
          sqm: '',
          bankList: [],
          seRegionList: [],
          regionList: [],
          djzx: ''
        },
        dataRule: {
                    djzx: [
            { required: true, message: '登记中心不能为空', trigger: 'blur' }
          ],
          sqm: [
            { required: true, message: '网厅授权码不能为空', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '区县不能为空', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '被查询人名称不能为空', trigger: 'blur' }
          ]

        }
      }
    },
    methods: {
      init (id) {
        this.visible = true

        this.$http({
          url: this.$http.adornUrl(`/bdc/bdcpurchase/item/list`),
              method: 'get',
              params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataForm.bankList = data.bankList
              this.dataForm.seRegionList = data.regionList
            }
        })

        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()

        })
      },

      selectChanged(value){
          this.dataForm.region = '';
          this.$http({
          url: this.$http.adornUrl(`/sys/bdcregion/listByLevle`),
              method: 'get',
              params: this.$http.adornParams({'upregion':value})
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataForm.regionList = data.list
            }
        })
      }
      ,
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.submitLoading = true
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcpurchase/send`),
              method: 'post',

              data: this.$http.adornData({
                'region': this.dataForm.region,
                'sqm': this.dataForm.sqm,
                'name': this.dataForm.name,
                'idcode': this.dataForm.idcode,
                'seRegion': this.dataForm.seRegion
                // 'djzx': this.dataForm.djzx
              })

            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '查询成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
              this.submitLoading = false
            }).catch(err => {
              this.submitLoading = false;
              console.error(err);
              this.$message.error('系统异常')              
            }); 
          }
        })
      }
    }
  }
</script>
